<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<ul class="sitemap">
<li><a href="<?=$curHost?>trang-chu.html">Trang Chủ</a></li>
<li><a href="<?=$curHost?>gioi-thieu.html">Giới thiệu</a></li>
<li><a href="<?=$curHost?>lien-he.html">Liên hệ</a></li>
</ul>
<?php
require_once "urllist.php";
$sitemap = fopen("sitemap.xml", "w+");
fwrite($sitemap, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
fwrite($sitemap, "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\">\n");
fwrite($sitemap,
"<url>\n
  <loc>".$curHost."</loc>\n
  <changefreq>always</changefreq>\n
  <priority>1.00</priority>\n
</url>\n
<url>\n
  <loc>".$curHost."trang-chu.html</loc>\n
  <changefreq>always</changefreq>\n
  <priority>0.80</priority>\n
</url>\n
<url>\n
  <loc>".$curHost."gioi-thieu.html</loc>\n
  <changefreq>always</changefreq>\n
  <priority>0.80</priority>\n
</url>\n
<url>\n
  <loc>".$curHost."lien-he.html</loc>\n
  <changefreq>always</changefreq>\n
  <priority>0.80</priority>\n
</url>\n
");?>
<ul class="sitemap">
<?
if($cat_pro){
	foreach($cat_pro as $cat_p){
		fwrite($sitemap, "<url>\n");
		fwrite($sitemap, "  <loc>".$curHost.str_replace(array('--','--'), '-', utf8_to_ascii($cat_p['name'])).'/'.
		str_replace(array('--','--'), '-', utf8_to_ascii($cat_p['seo_key']!='' ? $cat_p['seo_key'] : $cat_p['name']))."/7/".$cat_p['id'].".html</loc>\n");
		fwrite($sitemap, "  <changefreq>always</changefreq>\n");
		fwrite($sitemap, "  <priority>0.8</priority>\n");
		fwrite($sitemap, "</url>\n");
		echo "<li><a href='".$curHost.str_replace(array('--','--'), '-', utf8_to_ascii($cat_p['name'])).'/'.str_replace(array('--','--'), '-', utf8_to_ascii($cat_p['seo_key']!=''?$cat_p['seo_key']:$cat_p['name']))."/7/".$cat_p['id'].".html'>".$cat_p['name']."</a>";
		if($top_pro){?>
        	<ul>
			<?
			foreach($top_pro as $top_p){
				if($top_p['parent_id']==$cat_p['id']) 
                    echo "<li><a href='".$curHost.str_replace(array('--','--'), '-', utf8_to_ascii($cat_p['seo_key'] != '' ? $cat_p['seo_key'] : $cat_p['name'])).'/'.str_replace(array('--','--'), '-', utf8_to_ascii($top_p['seo_key']!= '' ? $top_p['seo_key'] : $top_p['name']))."/1/".$top_p['id'].".html'>".$top_p['name']."</a></li>";
				fwrite($sitemap, "<url>\n");
				fwrite($sitemap, "  <loc>".$curHost.str_replace(array('--','--'), '-', $parseokey[$cat_p['parent_id']] != '' ? $parseokey[$cat_p['parent_id']] : $parname[$cat_p['parent_id']]).'/'.str_replace(array('--','--'), '-', utf8_to_ascii($top_p['seo_key']!= '' ? $top_p['seo_key'] : $top_p['name']))."/1/".$top_p['id'].".html</loc>\n");
				fwrite($sitemap, "  <changefreq>always</changefreq>\n");
				fwrite($sitemap, "  <priority>0.8</priority>\n");
				fwrite($sitemap, "</url>\n");
			}?>
        	</ul>
        <?
		}?>
        </li>
        <?
	}
}?>
</ul>
<?
//Site_map($cat_pro,"product");
Site_map($cat_news,"news");
fwrite($sitemap, "</urlset> \n");
fclose($sitemap);
function Site_map($arrItem, $type="", $parent_id = "",$class=""){
	global $curHost;
	global $sitemap;
	global $top_news;
	global $top_pro;
	$_return = '';
	echo '<ul class="sitemap">';
	$class = $class!="" ? $class : "";
	$parent_id = $parent_id != '' ? $parent_id : 1;
	for($i=0; $i<count($arrItem); $i++){
		if($arrItem[$i]['parent_id'] == $parent_id){
			if(countArray($arrItem,'parent_id',$arrItem[$i]['id'])){$dem=1;}
			if($type=='news'){
				if($dem>0){$MenuPage = "/6/";}else{$MenuPage = "/2/";}
				$link = $curHost.str_replace(array('--','--'), '-', utf8_to_ascii($arrItem[$i]['name'])).'/'.str_replace(array('--','--'), '-', utf8_to_ascii($arrItem[$i]['seo_key']!=''?$arrItem[$i]['seo_key']:$arrItem[$i]['name'])).$MenuPage.$arrItem[$i]['id'].".html";
				echo "<li><a href='".$link."'>".$arrItem[$i]['name']."</a><ul>";
					foreach($top_news as $itemnews){
						if($itemnews['parent_id']==$arrItem[$i]['id']){
							echo "<li><a href='".$curHost.str_replace(array('--','--'), '-', utf8_to_ascii($itemnews['seo_key']!=''?$itemnews['seo_key']:$itemnews['name'])).'/'.str_replace(array('--','--'), '-', utf8_to_ascii($itemnews['name'])).$MenuPage.$itemnews['id'].".html'>".$itemnews['name']."</a></li>";
							fwrite($sitemap, "<url>\n");
							fwrite($sitemap, "  <loc>".$curHost.str_replace(array('--','--'), '-', utf8_to_ascii($itemnews['seo_key']!=''?$itemnews['seo_key']:$itemnews['name'])).'/'.str_replace(array('--','--'), '-', utf8_to_ascii($itemnews['name'])).$MenuPage.$itemnews['id'].".html</loc>\n");
							fwrite($sitemap, "  <changefreq>always</changefreq>\n");
							fwrite($sitemap, "  <priority>0.8</priority>\n");
							fwrite($sitemap, "</url>\n"); 
						}
					}
				echo "</ul></li>";
				
			}else{
				if($dem>0){$MenuPage = "/4/";}else{$MenuPage = "/7/";}
				$link = $curHost.str_replace(array('--','--'), '-', utf8_to_ascii($arrItem[$i]['name'])).'/'.str_replace(array('--','--'), '-', utf8_to_ascii($arrItem[$i]['seo_key']!=''?$arrItem[$i]['seo_key']:$arrItem[$i]['name'])).$MenuPage.$arrItem[$i]['id'].".html";
				echo "<li><a href='".$link."'>".$arrItem[$i]['name']."</a><ul>";
					foreach($top_pro as $itempro){
						if($itempro['parent_id']==$arrItem[$i]['id']){
							echo "<li><a href='".$curHost.str_replace(array('--','--'), '-', utf8_to_ascii($itempro['name'])).'/'.str_replace(array('--','--'), '-', utf8_to_ascii($itempro['seo_key']!=''?$itempro['seo_key']:$itempro['name'])).$MenuPage.$itempro['id'].".html'>".$itempro['name']."</a></li>";
							fwrite($sitemap, "<url>\n");
							fwrite($sitemap, "  <loc>".$curHost.str_replace(array('--','--'), '-', utf8_to_ascii($itempro['name'])).'/'.str_replace(array('--','--'), '-', utf8_to_ascii($itempro['seo_key']!=''?$itempro['seo_key']:$itempro['name'])).$MenuPage.$itempro['id'].".html</loc>\n");
							fwrite($sitemap, "  <changefreq>always</changefreq>\n");
							fwrite($sitemap, "  <priority>0.8</priority>\n");
							fwrite($sitemap, "</url>\n");
						}
					}
				echo "</ul></li>";
			}
			
			$_return.=$link;
			$_return.=fwrite($sitemap, "<url>\n");
			$_return.=fwrite($sitemap, "  <loc>".$link."</loc>\n");
			$_return.=fwrite($sitemap, "  <changefreq>always</changefreq>\n");
			$_return.=fwrite($sitemap, "  <priority>0.8</priority>\n");
			$_return.=fwrite($sitemap, "</url>\n"); 
			$_return.=Site_map($arrItem, $type, $arrItem[$i]['id']);
			$dem=0;
			
		}
	}		
	echo "</ul>";
	return $_return;
}
?>
<style type="text/css">
.sitemap{
	display:block;
	margin-left:20px;
}
.sitemap li{
	line-height:25px;
}
.sitemap li:hover{
	color:#DA1713;
}
.sitemap li a{
	color:#757575;
	text-decoration:none;
}

.sitemap li ul li{
	color:#757575;
}
.sitemap li ul li:hover{
	color:#DA1713;
}
.sitemap li ul{
	display:block;
	margin-left:20px;
}

.sitemap li a:hover{
	color:#DA1713;
}
</style>